#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
using namespace std;
void sortColors(vector<int>& nums) 
{
	int left=-1,i=0,right=nums.size()-1;
	while (i < right)
	{
		if (nums[i] == 0)
			swap(nums[++left], nums[i++]);
		else if (nums[i] == 1)
			i++;
		else
			swap(nums[--right], nums[i]);
	}
}
void _sortArray(vector<int>& nums,int l,int r)
{
	if (l >= r)
	{
		return;
	}
	int key = nums[rand() % (r - l + 1) + l];
	int left = -1, i = 0, right = nums.size();
	while (i < right)
	{
		if (nums[i] < key)
			swap(nums[++left], nums[i++]);
		else if (nums[i] == key)
			i++;
		else
			swap(nums[--right], nums[i]);
	}
	_sortArray(nums, l, left);
	_sortArray(nums,right,r);
}
vector<int> sortArray(vector<int>& nums)
{
	srand(time(nullptr));
	_sortArray(nums, 0, nums.size() - 1);
	return nums;
}
int _findKthLargest(vector<int>& nums,int l,int r, int k)
{
	if (l == r)
	{
		return nums[l];
	}
	int key = nums[rand() % (r - l + 1) + l];
	int left = l - 1, i = l, right = r + 1;
	while (i < right)
	{
		if (nums[i] < key)
			swap(nums[++left], nums[i++]);
		else if (nums[i] == key)
			i++;
		else
			swap(nums[--right], nums[i]);
	}
	int a = left - l + 1, b = right - left - 1, c = r - right + 1;
	if (c >= k)
		_findKthLargest(nums, right, r, k);
	else if (b + c >= k)
		return key;
	else
		_findKthLargest(nums, l, left, k-(b+c));

}
int findKthLargest(vector<int>& nums, int k) 
{
	srand(time(nullptr));
	return _findKthLargest(nums,0,nums.size()-1, k);
}
void _smallestK(vector<int>& arr,int l,int r, int k)
{
	if (l >= r)
	{
		return;
	}
	int key = arr[rand() % (r - l + 1) + l];
	int left = l - 1, i = l, right = r + 1;
	while (i < right)
	{
		if (arr[i] < key)
			swap(arr[++left], arr[i++]);
		else if (arr[i] == key)
			i++;
		else
			swap(arr[--right], arr[i]);
	}
	int a = left - l + 1, b = right - left - 1, c = r - right + 1;
	if (a >= k)
		_smallestK(arr, l, left, k);
	else if (a + b >= k)
		return;
	else
		_smallestK(arr, right, r, k-(a+b));
}
vector<int> smallestK(vector<int>& arr, int k) 
{
	srand(time(nullptr));
	_smallestK(arr, 0, arr.size() - 1, k);
	return { arr.begin(),arr.begin() + k };
}
int main()
{

	return 0;
}